import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/cupertino.dart' hide Action;
import 'package:www.znpigai.teacher/home_page/homework_list_component/item/state.dart';
import 'package:www.znpigai.teacher/utils/nav.dart';

import 'action.dart';

Effect<HomeworkState> buildEffect() {
  return combineEffects(<Object, Effect<HomeworkState>>{
    AnswerAction.action: _onAction,
    AnswerAction.onClick: _onClick,
  });
}

void _onAction(Action action, Context<HomeworkState> ctx) {}

void _onClick(Action action, Context<HomeworkState> ctx) async {
  var answerId = ctx.state.id;
  var done;
  var url = '/correct/pub/view/machine/review.mvc?id=$answerId&ishomework=1';

  switch (ctx.state.status) {
    case "reject":
      done = await Navigator.of(ctx.context).pushNamed(Nav.WEB_PAGE,
          arguments: {'url': url, 'share': false, 'done': '去修改'});

      if (done != null) {
        Navigator.of(ctx.context)
            .pushNamed(Nav.ANSWER_EDIT, arguments: {'answer': ctx.state});
      }
      break;
    case "finish":
    case "remark":
      Navigator.of(ctx.context).pushNamed(Nav.WEB_PAGE,
          arguments: {'url': url, 'share': true, 'done': ''});
      break;
    case "notSubmit":
    case "notStart":
    case "underway":
    default:
      Navigator.of(ctx.context)
          .pushNamed(Nav.ANSWER_EDIT, arguments: {'answer': ctx.state});
  }
}
